package action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import biz.CustomerBiz;
import entity.Customer;

/**
 * @author 陈彬彬
 * @publish 2015-11-18 下午11:26:18
 * @category 客户控制层类
 */
@Controller
public class CustomerAction extends BaseAction {
	@Resource
	private CustomerBiz biz;
	
	private Customer cus;
	private List<Customer> cuss;
	public Customer getCus() {
		return cus;
	}
	public void setCus(Customer cus) {
		this.cus = cus;
	}
	public List<Customer> getCuss() {
		return cuss;
	}
	public void setCuss(List<Customer> cuss) {
		this.cuss = cuss;
	}
	
	//增
		public String add(){
			if(biz.add(cus)){
				this.setMsg("添加客户成功");	
			}else{
				this.setMsg("添加客户失败");		
			}
			return "edit";
		}
		//删
		public String del(){
			if(biz.del(getId())){
				this.setMsg("删除客户成功！");
			}else{
				this.setMsg("删除客户失败！");
			}
			return list();
		}
		//改
		public String update(){
			if(biz.update(cus)){
				this.setMsg("更新客户信息成功！");
				return list();
			}else{
				this.setMsg("更新客户信息失败！");
				return "edit";
			}
		}
		//查
		public String list(){
			int empid=getCurUser().getEmpid();
			cuss=biz.queryByPage(getPage(), 5,empid);
			int count=biz.count(empid);
			setTpage(count%5==0?count/5:(count/5+1));
			return "list";
		}
		
		public String show(){
			cus=biz.get(getId());
			if(cus==null){
				setMsg("该客户不存在！");
				return list();
			}
			return "edit";
		}
}
